package com.h3c.nem.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.h3c.nem.dto.SdDeptDTO;
import com.h3c.nem.entity.SdDept;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * Copyright (C), 2020-2020, h3c
 * FileName: SdDeptMapper
 *
 * @Author: l22886
 * @Date: 2022-01-19
 * Description: sd_dept mapper
 * Version: 1.0
 */
public interface SdDeptMapper extends BaseMapper<SdDept> {

    /**
     * @title: queryListByFuzzy
     * @description: 模糊列表查询
     * @params: [ SdDept ]
     * @return: java.util.List
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    public List<SdDept> queryListByFuzzy(SdDept SdDept);

    /**
     * @title: queryListByFuzzy
     * @description: 精确列表查询
     * @params: [ SdDept ]
     * @return: java.util.List
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    public List<SdDept> queryList(SdDept SdDept);

    /**
     * @title: updateSdDept
     * @description: 更新
     * @params: [ SdDept ]
     * @return: java.lang.Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    public Integer updateSdDept(SdDept sdDept);

    public Integer updateSdDeptNem(SdDeptDTO sdDeptDTO);

    public Integer updateSdDeptManager(SdDept sdDept);

    /**
     * @title: insertSdDept
     * @description: 插入
     * @params: [ SdDept ]
     * @return: java.lang.Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    public Integer insertSdDept(SdDept SdDept);

    /**
     * @title: deleteSdDept
     * @description: 删除
     * @params: [ SdDept ]
     * @return: java.lang.Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    public Integer deleteSdDept(SdDept SdDept);

    @Select("select dept_id from sd_dept where dept_name =#{deptName} and dept_level =#{deptLevel}")
    Integer queryDeptIdByDeptNameAndDeptLevel(@Param("deptName") String deptName, @Param("deptLevel") Integer deptLevel);

    @Select("select 1 from sd_dept where dept_manager_id like concat('%',#{workerId},'%') limit 1")
    public Integer checkDeptManager(@Param("workerId") String workerId);

    @Select("select 1 from sd_dept where bp_user_id like concat('%',#{workerId},'%') and dept_level =#{deptLevel} limit 1")
    public  Integer checkDept1Bp(@Param("workerId") String workerId, @Param("deptLevel") Integer deptLevel);


    @Select("select dept_manager_id as old_worker_id from sd_dept ${ew.customSqlSegment}")
    List<Map<String, Object>> selectEmpCodes(@Param(Constants.WRAPPER) LambdaQueryWrapper<SdDept> sdDeptLambdaQueryWrapper);
}
